package ar.edu.unq.leezsi.model;

import ar.edu.unq.leezsi.html.Component;

public class Model<T> {

	private Object target;
	private Component<T> component;

	public Model(Model<?> target) {
		this.target = target;
	}

	public Model(Object target) {
		this.target = target;
	}

	public <R> R get(String property) {
		if (this.getTarget() instanceof Model) {
			return ((Model<?>) this.getTarget()).get(property);
		}
		return new PropertyResolver(this.getTarget()).get(property);
	}

	public Component<T> getComponent() {
		return this.component;
	}

	public Object getTarget() {
		return this.target;
	}

	public void set(String property, Object value) {
		if (this.getTarget() instanceof Model) {
			((Model<?>) this.getTarget()).set(property, value);
		}
		new PropertyResolver(this.getTarget()).set(property, value);
	}

	public void setComponent(Component<T> component) {
		this.component = component;
	}

	public void setTarget(Object target) {
		this.target = target;
	}

	@Override
	public String toString() {

		return this.getTarget().toString();
	}
}
